﻿{extend name="base"/}
{block name="main"}
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
            <div class="tabBar clearfix">
            <span  onclick="window.location.href='{:url('goods/goods_attr_mod')}'">分类管理</span>
            <span class="current" onclick="window.location.href='{:url('goods/goods_spec')}'">规格管理</span>
            <span  onclick="window.location.href='{:url('goods/attributelist')}'">属性管理</span>
              </div>
            <a href="{:url('goods/goods_spec_add')}" class="n_tab_add">添加规格</a>
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px; display:none;" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
            <div class="cl"></div>
        </div>
 <div class="cl pd-5 bg-1 bk-gray mt-20">
        <form class="Huiform" method="post" action="__CONF_SITE__admin/goods/goods_spec" target="_self" style=" padding: 15px;">
            <div class="text-c"> 规格名称：
               <input type="text" class="input-text" value="{$search_text}" style="width:250px" placeholder="规格名称"  name="search_text">
                <button type="submit" class="btn btn-search radius"  name=""><i class="Hui-iconfont">&#xe665;</i> 搜规格</button>
            </div>
        </form>
</div>
        <table class="table table-border table-bordered table-bg">
            <thead>
            <tr>
                <th scope="col" colspan="9">规格列表</th>
            </tr>
            <tr class="text-c">
                <th width="40">规格名称</th>
                <th width="150">规格属性</th>
                <th width="150">状态</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="list" id="vo"}
            <tr class="text-c">
                <td>{$vo['spec_name']}</td>
                <td>{$vo['spec_value_name_list']}</td>
                <td>
                    {if $vo['is_visible']==1}
                    <a style="text-decoration:none" onClick="goods_spec_stop(this,'{$vo.spec_id}','is_visible')" is_visible="0" href="javascript:;" title="已启用"><span class="label label-success radius">已启用</span></a>
                    {/if}
                    {if $vo['is_visible']==0}
                    <a style="text-decoration:none" onClick="goods_spec_start(this,'{$vo.spec_id}','is_visible')" href="javascript:;" is_visible="1" title="已停用"><span class="label label-default radius">已停用</span></a>
                    {/if}
                </td>
                <td>
                    <a title="编辑" href="javascript:;" onclick="goods_spec_edit('规格编辑','__CONF_SITE__admin/goods/goods_spec_edit&spec_id={$vo.spec_id}','800','500')" class="ml-5" style="text-decoration:none"><i  style="font-size: 20px;" class="Hui-iconfont">&#xe6df;</i></a>
                    <a title="删除" href="javascript:;" onclick="goods_spec_del(this,'{$vo.spec_id}')" class="ml-5" style="text-decoration:none"><i  style="font-size: 20px;" class="Hui-iconfont">&#xe6e2;</i></a>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
    </article>
    <div class="n_page_no">
        {$page}
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	/*
	 参数解释：
	 title	标题
	 url		请求的url
	 id		需要操作的数据id
	 w		弹出层宽度（缺省调默认值）
	 h		弹出层高度（缺省调默认值）
	 */
	/*规格-删除*/
    function goods_spec_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //此处请求后台程序
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/deleteGoodsSpec')}",
                data : { 'spec_id' : id.toString() },
                dataType : "json",
                success : function(data) {
                    if (data['code'] > 0) {
                        layer.msg(data['message'], {icon: 1, time: 1000},function () {
                            window.parent.location.reload();
                        });
                    }else if(data['code'] == 0){
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }else if(data['code'] == -1){
                        layer.msg('当前规格正在使用中，不能删除！', {icon: 2, time: 1000});
                    }
                }
            });
        });
    }
	/*规格-编辑*/
    function goods_spec_edit(title,url,w,h){
        layer_show(title,url,w,h);
    }
	/*规格-停用*/
    function goods_spec_stop(obj,id,name){
        layer.confirm('确认要停用吗？',function(index){
            //此处请求后台程序，下方是成功后的处理……
            var value = $(obj).attr("is_visible");
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/setGoodsSpecField')}",
                data : {
                    "spec_id" : id,'value' : value,'name':name
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        layer.msg('已停用!',{icon: 5,time:500},function () {
                            window.parent.location.reload();
                        });
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
	/*规格-启用*/
    function goods_spec_start(obj,id,name){
        layer.confirm('确认要启用吗？',function(index){
            //此处请求后台程序，下方是成功后的处理……
            var value = $(obj).attr("is_visible");
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/setgoodsspecfield')}",
                data : {
                    "spec_id" : id,'value' : value,'name':name
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        layer.msg('已启用!',{icon: 1,time:500},function () {
                            window.parent.location.reload();
                        });
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
</script>
{/block}